package eclipse.weibo.service;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;

import weibo4j.util.DebugPrn;

import eclipse.weibo.modle.WeiboView;

public class ShowStatusObserver implements Observer {
    private static DebugPrn dp = new DebugPrn(ShowStatusObserver.class.getName());
    private IWorkbenchPage page;
    private Display display;

    public ShowStatusObserver(IWorkbenchPage page, Display display) {
        this.page = page;
        this.display = display;
    }

    public void update(Observable o, Object arg) {
        display.asyncExec(new TTHread((List<?>) arg));
    }

    class TTHread extends Thread {
        private List<?> list;

        public TTHread(List<?> list) {
            this.list = list;
        }

        public void run() {
            try {
                String name = WeiboView.class.getName();
                IViewPart viewPart = page.findView(name);
                if (viewPart == null) {
                    viewPart = page.showView(WeiboView.class.getName());
                }
                if (viewPart instanceof WeiboView) {
                    ((WeiboView) viewPart).showContent(list);
                }
                viewPart.setFocus();
            } catch (Exception ex) {
                dp.error(ex, ex);
            }
        }
    }
}